<%@ page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ajax</title>
<script type="text/javascript"> 
var xmlHttp; 
function GetXmlHttpObject(){ 
	if(window.XMLHttpRequest){ 
		xmlhttp=new XMLHttpRequest(); 
	}else{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} 
	return xmlhttp; 
} 
function getLabelsGet(){ 
	xmlHttp=GetXmlHttpObject(); 
	if (xmlHttp==null){ 
		alert('您的浏览器不支持AJAX！'); 
		return; 
	} 
	var id = document.getElementById('id').value; 
	var url="${pageContext.request.contextPath}/ajax?name="+id; 
	xmlHttp.open("GET",url,true); 
	xmlHttp.onreadystatechange=getOkGet;//发送事件后，收到信息了调用函数 
	xmlHttp.send(); 
}
function getOkGet(){ 
	if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ 
		alert(xmlHttp.readyState);
	} 
	if(xmlHttp.readyState==4 && xmlHttp.status==200){ 
		var d= xmlHttp.responseText; 
		document.getElementById('id').value=d;
	} 
} 
</script>
</head>
<body>
<input type="text" id="id" onchange="getLabelsGet()">
</body>
</html>